package com.sdkj.controller.law;

import java.util.Date;
import java.util.List;

import org.quartz.Scheduler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.sdkj.controller.base.BaseController;
import com.sdkj.service.base.quartz.ScheduleJobService;
import com.sdkj.service.law.LawRemindService;
import com.sdkj.service.law.LawReceiveService;
import com.sdkj.util.DateUtil;
import com.sdkj.util.PageData;

@Component("lawJob")
public class LawJob extends BaseController{
	
	@Autowired
	private LawReceiveService lawreceiveService;
	@Autowired
	private LawRemindService lawAgService;
	@Autowired
	private ScheduleJobService scheduleJobService;
	
	public void remind(){
		try {
			List<PageData> lawList = lawreceiveService.listAll(new PageData());
			for(PageData pd : lawList){
				Date endDate = (Date)pd.get("receive_endtime");
				PageData pdStatus = scheduleJobService.findById(pd);
				String status = pdStatus.getString("job_status");
				long days = DateUtil.getDaySub(DateUtil.getTime(),DateUtil.getTime(endDate));
				PageData pd2 = new PageData();
				if (days <= 7 && days >= 6) {
					if (!status.equals("7")&&status != "7") {
						pd2.put("remind_id", this.get32UUID());
						pd2.put("remind_type", pd.getString("receive_type"));
						pd2.put("remind_person", pd.getString("revision_person"));
						pd2.put("remind_title", pd.getString("receive_title"));
						pd2.put("remind_time", DateUtil.getTime());
						pd2.put("remind_remark", "七天到期");
						pd2.put("user_id", pd.getString("user_id"));
						scheduleJobService.edit("7",pd.getString("job_id"));
						lawAgService.save(pd2);
					}
				}if (days <= 3 && days >= 2) {
					if (!status.equals("3")&&status != "3") {
						pd2.put("remind_id", this.get32UUID());
						pd2.put("remind_type", pd.getString("receive_type"));
						pd2.put("remind_person", pd.getString("revision_person"));
						pd2.put("remind_title", pd.getString("receive_title"));
						pd2.put("remind_time", DateUtil.getTime());
						pd2.put("remind_remark", "三天到期");
						pd2.put("user_id", pd.getString("user_id"));
						scheduleJobService.edit("3",pd.getString("job_id"));
						lawAgService.save(pd2);
					}
				}if (days <= 1 &&days >= 0) {
					if (!status.equals("2")&&status != "2") {
						System.out.println("=========================================");
						System.out.println("进入days 为1  这个status" + status);
						pd2.put("remind_id", this.get32UUID());
						pd2.put("remind_type", pd.getString("receive_type"));
						pd2.put("remind_person", pd.getString("revision_person"));
						pd2.put("remind_title", pd.getString("receive_title"));
						pd2.put("remind_time", DateUtil.getTime());
						pd2.put("remind_remark", "一天到期");
						pd2.put("user_id", pd.getString("user_id"));
						scheduleJobService.edit("2",pd.getString("job_id"));
						lawAgService.save(pd2);
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
